home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.2 KB | 180 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWAccBuf.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWACCBUF_H
- #include "FWAccBuf.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CPrivFileAccessBuffer
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::FW_CPrivFileAccessBuffer
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFileAccessBuffer::FW_CPrivFileAccessBuffer(long capacity) :
- fType(kInvalid),
- fBuffer(0),
- fCapacity(capacity),
- fInitialPosition(0),
- fValidBytes(0),
- fBytesWritten(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::FW_CPrivFileAccessBuffer
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFileAccessBuffer::FW_CPrivFileAccessBuffer(const FW_CPrivFileAccessBuffer& otherBuffer) :
- fType(kInvalid),
- fBuffer(0),
- fCapacity(otherBuffer.fCapacity),
- fInitialPosition(0),
- fValidBytes(0),
- fBytesWritten(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::~FW_CPrivFileAccessBuffer
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFileAccessBuffer::~FW_CPrivFileAccessBuffer()
- {
- delete [] fBuffer;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFileAccessBuffer::Initialize(int type,
- long filePosition,
- long validBytes)
- {
- fType = type;
- if (fBuffer == 0)
- fBuffer = new char[fCapacity];
- fInitialPosition = filePosition;
- fValidBytes = validBytes;
- fBytesWritten = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFileAccessBuffer& FW_CPrivFileAccessBuffer::operator=(const FW_CPrivFileAccessBuffer& otherBuffer)
- {
- if (this != &otherBuffer)
- {
- if (fCapacity != otherBuffer.fCapacity)
- {
- delete [] fBuffer;
-
- fBuffer = NULL;
- fCapacity = otherBuffer.fCapacity;
- fType = kInvalid;
- }
- }
-
- return (*this);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::ReadPeek
- //----------------------------------------------------------------------------------------
-
- void* FW_CPrivFileAccessBuffer::ReadPeek(long currentPosition,
- long& availableReadBytes)
- {
- void * source = 0;
-
- availableReadBytes = 0;
-
- if (fType == kReadPeek)
- {
- long offsetInBuffer = currentPosition - fInitialPosition;
- if ((offsetInBuffer >= 0) && (offsetInBuffer < fValidBytes))
- {
- source = fBuffer + offsetInBuffer;
- availableReadBytes = fValidBytes - offsetInBuffer;
- }
- }
-
- return source;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::ReadPeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFileAccessBuffer::ReadPeekAdvance(long currentPosition,
- long bytesRead)
- {
- FW_ASSERT(fType == kReadPeek);
- FW_ASSERT(fInitialPosition <= currentPosition);
- FW_ASSERT(bytesRead >= 0);
- FW_ASSERT((currentPosition - fInitialPosition + bytesRead) <= fValidBytes);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::WritePeek
- //----------------------------------------------------------------------------------------
-
- void* FW_CPrivFileAccessBuffer::WritePeek(long currentPosition,
- long& availableWriteBytes)
- {
- void * destination = 0;
-
- availableWriteBytes = 0;
-
- if (fType == kWritePeek)
- {
- long offsetInBuffer = currentPosition - fInitialPosition;
- if ((fBytesWritten == offsetInBuffer) && (fBytesWritten < fValidBytes))
- {
- destination = fBuffer + fBytesWritten;
- availableWriteBytes = fValidBytes - fBytesWritten;
- }
- }
-
- return destination;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFileAccessBuffer::WritePeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFileAccessBuffer::WritePeekAdvance(long currentPosition,
- long bytesWritten)
- {
- FW_ASSERT(fType == kWritePeek);
- FW_ASSERT(fBytesWritten == (currentPosition - fInitialPosition));
- FW_ASSERT(bytesWritten >= 0);
- FW_ASSERT((fBytesWritten + bytesWritten) <= fValidBytes);
-
- fBytesWritten += bytesWritten;
- }
-
-